package cn.edu.njnu.service;

import cn.edu.njnu.mapper.GroupMapper;
import cn.edu.njnu.pojo.Result;
import cn.edu.njnu.pojo.ResultFactory;
import cn.edu.njnu.vo.GroupInfoVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class GroupService {
    private final GroupMapper groupMapper;
    public Result getMemberIdList(Integer groupId){
        List<Integer> groupMember = groupMapper.findGroupMember(groupId);
        if (groupMember.size()>0){
            return ResultFactory.buildSuccessResult("查询组员成功",groupMember);
        }
        return ResultFactory.buildFailResult("该组不存在");
    }
    public Result getGroupInfo(Integer userId){
        List<GroupInfoVo> infoList = groupMapper.getGroupInfo(userId);
        if (infoList.size()>0){
            return ResultFactory.buildSuccessResult("查询用户组信息成功",infoList);
        }
        return ResultFactory.buildFailResult("用户没有相关的组");
    }
}
